from django.db import models
from django.contrib.auth.models import AbstractUser
from imagekit.models import ProcessedImageField
from imagekit.processors import ResizeToFill
from mdeditor.fields import MDTextField

# 用户表
class User(AbstractUser):
    create_time = models.DateField(verbose_name='创建时间', auto_now_add=True)
    mobile = models.CharField(verbose_name='手机号', max_length=11, unique=True, null=True)
    sex = models.CharField(verbose_name='性别', max_length=2, null=True)
    age = models.IntegerField(verbose_name='年龄', null=True)
    faculty = models.CharField(verbose_name='学院', max_length=10, null=True)
    major = models.CharField(verbose_name='专业', max_length=10, null=True)
    come_from = models.CharField(verbose_name='来自', max_length=2, null=True)
    profile = models.CharField(verbose_name='简介', max_length=50, null=True)
    avatar = ProcessedImageField(upload_to='avatar',
                                 default='avatar/default.png',
                                 verbose_name='头像',
                                 #图片将处理成100 x 100的尺寸
                                 processors=[ResizeToFill(100,100)],)


    def __str__(self):
            return self.username

# 分类表
class Kind(models.Model):
    # k_id = models.CharField(verbose_name='分类id', max_length=16)
    k_name = models.CharField(verbose_name='分类名称', max_length=16)


# 帖子表
class Topic(models.Model):
    t_uid = models.ForeignKey(User, on_delete=models.CASCADE)
    t_kind = models.ForeignKey(Kind, on_delete=models.CASCADE)
    create_time = models.DateField(verbose_name='创建时间', auto_now_add=True)
    # t_photo = models.CharField(verbose_name='帖子图片', max_length=128, null=True)
    t_content = MDTextField(max_length=1000)
    t_title = models.CharField(verbose_name='帖子标题', max_length=64)
    t_introduce = models.CharField(verbose_name='帖子简介', max_length=256)
    recommend = models.BooleanField(verbose_name='是否推荐', default=False)

# 点赞表
class Like(models.Model):
    tid = models.ForeignKey(Topic, on_delete=models.CASCADE)
    uid = models.ForeignKey(User, on_delete=models.CASCADE)
    like = models.BooleanField(default=True)

# 回复表
class Reply(models.Model):
    # r_tid = models.CharField(verbose_name='帖子id', max_length=16)
    r_tid = models.ForeignKey(Topic, on_delete=models.CASCADE)
    # r_uid = models.CharField(verbose_name='发表者id', max_length=16)
    r_uid = models.ForeignKey(User, on_delete=models.CASCADE)
    r_photo = models.CharField(verbose_name='回复的图片', max_length=128, null=True)
    r_time = models.DateField(verbose_name='留言时间', auto_now_add=True)
    r_content = models.CharField(verbose_name='回复内容', max_length=256)




# 公告表
class Announcement(models.Model):
    # a_id = models.CharField(verbose_name='公告id', max_length=16)
    a_title = models.CharField(verbose_name='公告标题', max_length=64)
    a_content = models.CharField(verbose_name='公告内容', max_length=3000, null=True)
